﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Presentation
{
    public partial class UserControlOption : UserControl
    {
        public UserControlOption()
        {
            InitializeComponent();
            LoadDuLieu();
            _InputShortCut = new BUS.CInputKeyShortcut();
            _InputShortCut.Install(ref txtEnDisApp);
            _InputShortCut.Install(ref txtStopRunning);
        }
        BUS.CInputKeyShortcut _InputShortCut;

        private void LoadDuLieu()
        {
            cmbDataPath.Items.Add(BUS.COption.DataPath);
            cmbDataPath.SelectedIndex = 0;
            txtEnDisApp.Text = BUS.COption.EnOrDisApp;
            txtStopRunning.Text = BUS.COption.StopRunning;
            nudDelayDefault.Value = BUS.COption.DefaultDelay;
        }

        private void cmdReset_Click(object sender, EventArgs e)
        {
            LoadDuLieu();
        }

        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtStopRunning.Text == txtEnDisApp.Text)
            {
                MessageBox.Show("Endable/Disable Application not be identical to stop runing!", "Warning", MessageBoxButtons.OK);
            }
            BUS.COption.DataPath = cmbDataPath.Text;
            BUS.COption.EnOrDisApp = txtEnDisApp.Text;
            BUS.COption.StopRunning = txtStopRunning.Text;
            BUS.COption.DefaultDelay = Convert.ToInt32(nudDelayDefault.Value);
        }

        private void cmdBrower_Click(object sender, EventArgs e)
        {
            BUS.COption.GetPathData();
            bool _DaCo = false;
            for (int i = 0; i < cmbDataPath.Items.Count; i++)
                if (BUS.COption.DataPath == cmbDataPath.Items[i].ToString())
                {
                    _DaCo = true;
                    cmbDataPath.SelectedIndex = i;
                    break;
                }
            if (!_DaCo)
            {
                cmbDataPath.Items.Add(BUS.COption.DataPath);
                cmbDataPath.SelectedIndex = cmbDataPath.Items.Count - 1;
            }
        }

        private void cmdNew_Click(object sender, EventArgs e)
        {
            BUS.COption.SetPathData();
            bool _DaCo = false;
            for (int i = 0; i < cmbDataPath.Items.Count; i++)
                if (BUS.COption.DataPath == cmbDataPath.Items[i].ToString())
                {
                    _DaCo = true;
                    cmbDataPath.SelectedIndex = i;
                    break;
                }
            if (!_DaCo)
            {
                cmbDataPath.Items.Add(BUS.COption.DataPath);
                cmbDataPath.SelectedIndex = cmbDataPath.Items.Count - 1;
            }
        }
    }
}
